import "crvpuppet"


# Definition: at3_xrootd_fuse
#
#  Xrootd is a high performance network storage system widely used in high energy 
#  physics experiments such as ATLAS and ALICE. The underlying Xroot data transfer 
#  protocol provides highly efficient access to ROOT based data files. This class provides 
#  the basis for creating a simple Xrootd storage system consisting of one 
#  redirector node and one or more data server nodes.
#  
#  This installs and configures a read-only xrootdfs fuse mount for an existing xrootd cluster
#
# Parameters:
# 	- $webaddr: the web address to the cloud crv server
#   - $roleid: unique identifier of the role for this module
#
# CloudCRV Attributes:
#   - $fqdnRedirector : fully qualified domain name for the redirector
#   - $mountPoint - the mount point
#   - $storagePath: a directory containing internal Xrootd references to files in the system.
#      Default is '/atlas'
#   
# Actions:
#   - installs xrootd-fuse
#   - sets up the mount point
#   - mounts xrootd
#
# Requires:
#   - This has been tested on SL and SLC 5.5
#   
define at3_xrootd_fuse ($webaddr="", $roleid="") 
{
  
 
  
  if $AutoMode==true and $CloudCRV==true {
    $fqdnRedirector=get_provider_attr($webaddr,$roleid,"XROOTDRedirector")
    $ossLocalRoot=get_role_attr($webaddr,$roleid,"XROOTDOssLocalRoot")
    $mountPoint=get_role_attr($webaddr,$roleid,"XROOTDMountPoint")
    $storagePath=get_role_attr($webaddr,$roleid,"XROOTDStoragePath")
     
  }
  else
  {
	  $mountPoint='/xrootdfs/atlas'
	  $ossLocalRoot='/local/xrootd/a'
	  $storagePath='/atlas'
  }
  
  
  group { 'xrootd':
    ensure => present,
  }

  user { 'xrootd':
    ensure => present,
    gid    => 'xrootd',
    require=> Group['xrootd'],
  }

  # recursively make all the directories for the mount point 
  exec { "$mountPoint":
    command => "mkdir -p $mountPoint",
    creates => "$mountPoint",
    path    => ['/bin','/usr/bin'],
    require => [User['xrootd']],
    logoutput => true,
    onlyif => ["test -z `mount | grep xrootdfs`"],
  }

  exec { "chown xrootd:xrootd $mountPoint":
    path    => ['/bin','/usr/bin'],
    require => Exec["$mountPoint"],
    logoutput => true,
    onlyif => ["test -z `mount | grep xrootdfs`"],
  } 

  package { ['xrootd-server.x86_64','xrootd-client.x86_64','xrootd-fuse.x86_64','xrootd-debuginfo.x86_64','xrootd-libs.x86_64']:
      ensure => installed,
  }

  
  mount { "$mountPoint":
    atboot  => true,
    device  => "xrootdfs",
    dump    => 0,
    ensure  => mounted,
    fstype  => fuse,
    options => "rw,nonempty,rdr=xroot://${fqdnRedirector}:1094/${storagePath},uid=xrootd",
    pass    => 0,
    remounts  => false,
    require => [Package['xrootd-fuse.x86_64','xrootd-client.x86_64'],Exec["$mountPoint"]],
  } 
}


define at3_xrootd_fuse_reverse($webaddr, $roleid) {
  #set_role_attr($webaddr,$roleid,"ReverseProfileApplied","True")
}
